<?php
declare (strict_types=1);

namespace app\<module>\controller;

use app\<module>\service\<service>Service;
use app\<module>\validate\<service>Validate;

/**
 * <controller>控制器
 * Class <controller>
 * @package app\<module>\controller
 */
class <controller> extends Controller
{

    /**
     * @notes 获取列表
     * @return \think\response\Json
     */
    public function lists()
    {
        $params = request()->get();
        $service = new <service>Service();
        $result = $service->get<service>Lists($params, $this->page);
        return $this->success($result);
    }

    /**
     * @notes 添加
     * @return \think\response\Json
     */
    public function add()
    {
        $params = $this->checkPost(<validate>Validate::class, 'add');
        $service = new <service>Service();
        $result = $service->add<service>($params);
        if (false === $result) {
            return $this->fail($service->getError());
        }
        return $this->success('操作成功');
    }

    /**
     * @notes 编辑
     * @return \think\response\Json
     */
    public function edit()
    {
        $params = $this->checkPost(<validate>Validate::class, 'edit');
        $service = new <service>Service();
        $result = $service->edit<service>($params);
        if (false === $result) {
            return $this->fail($service->getError());
        }
        return $this->success('操作成功');
    }

    /**
     * @notes 获取详情
     * @return \think\response\Json
     */
    public function detail()
    {
        $params = $this->checkGet(<validate>Validate::class, 'id');
        $service = new <service>Service();
        $result = $service->get<service>Detail((int)$params['id']);
        return $this->success($result);
    }

    /**
     * @notes 删除
     * @return \think\response\Json
     */
    public function del()
    {
        $params = $this->checkPost(<validate>Validate::class, 'id');
        $service = new <service>Service();
        $service->del<service>((int)$params['id']);
        return $this->success('操作成功');
    }

}
